package com.ljkj.cordial.chat.ui.views;

import com.lanjiu.lib.imclient.bus.EventConstants;
import com.lanjiu.lib.imclient.bus.MessageEvent;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.lib.imclient.dto.user.TouristsUserDto;
import com.lanjiu.lib.imclient.dto.user.UserDto;
import com.lanjiu.lib.utils.log.Logger;
import com.ljkj.cordial.chat.ui.IView;

/**
 * @description:
 * @author: Panwei
 * @date: 2019/11/25 9:41
 */
public class SplashView extends IView {

    private SplashCallback mCallback;

    public SplashView(SplashCallback mCallback) {
        this.mCallback = mCallback;
    }

    public void doTouristsLogin() {
        doSendRequest(EventConstants.Action.LOGIN_TOURISTS);
    }

    @Override
    public void onMessageEventHandle(MessageEvent event) {
        Logger.print("SplashView", event.toString());
        if (EventConstants.Action.LOGIN_TOURISTS == event.action()) {
            UserDto user = null;
            if (checkIsSuccess(event.code(), event.data())) {
                TouristsUserDto touristsUser = Dto.fromJson(event.data(), TouristsUserDto.class);
                if (null != touristsUser) user = new UserDto(touristsUser);
            }
            if (null != mCallback)
                mCallback.onLoginCallback(event.code(), event.msg(), user);
        }
    }

    public interface SplashCallback {

        void onLoginCallback(int code, String msg, UserDto data);
    }
}
